package com.toman.toolbar;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.kingja.loadsir.callback.Callback;
import com.kingja.loadsir.core.LoadSir;
import com.kingja.loadsir.core.Transport;
import com.toman.R;
import com.toman.Util.NetworkUtils;
import com.toman.widget.callback.EmptyCallback;
import com.toman.widget.callback.ErrorCallback;
import com.toman.widget.callback.PostUtil;

import java.util.List;

/**
 * Created by 邹苏隆 on 2018/7/26.
 * description：
 */

public abstract class LoadingActivity extends ToolBarActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        initLoad();

    }

    protected abstract Activity getContent();

    public   void initLoad() {
        loadService = LoadSir.getDefault().register(getContent(), new Callback.OnReloadListener() {
            @Override
            public void onReload(final View v) {
                // Your can change the status out of Main thread.
                new Thread(new Runnable() {
                    @Override
                    public void run() {
//                        loadService.showCallback(LoadingCallback.class);
                        //do retry logic...
//                        load();

                        //callback
                    }
                }).start();
            }
        }).setCallBack(ErrorCallback.class, new Transport() {
            @Override
            public void order(Context context, View view) {
                TextView mTvEmpty = (TextView) view.findViewById(R.id.tv_empty);
//                mTvEmpty.setText("您还未添加"+mToolBarHelper.getTvTitle()+"~");
                Button mButton = (Button) view.findViewById(R.id.btn_retry);
                TextView tv_toolbar_title = (TextView) view.findViewById(R.id.tv_toolbar_title);
                tv_toolbar_title.setText(mToolBarHelper.getTvTitle());
//                mButton.setText("点击返回");
                Toolbar mToolbar=(Toolbar)view.findViewById(R.id.id_tool_bar);

                mToolbar.setNavigationOnClickListener(new View.OnClickListener()
                {
                    @Override
                    public void onClick(View view)
                    {
                        finish();
                    }
                });
                mButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {

                        Intent intent=getIntent();
                        intent.setClass(getContent(),getContent().getClass());
startActivity(intent);

                        finish();
                    }
                });
            }
        });
        if (!NetworkUtils.checkNetState(getContent())){
                    PostUtil.postCallbackDelayed(loadService, ErrorCallback.class);

        }
    }
    public void isEmpty(  List list, TextView  mMangeNodata){
        if (list.size() == 0) {
            mMangeNodata.setVisibility(View.VISIBLE);
        } else {
            mMangeNodata.setVisibility(View.GONE);
        }
        loadService.showSuccess();

    }





}
